//
//  focus_TableViewCell.m
//  SoundPill
//
//  Created by 宋鹏鹏 on 15/4/1.
//  Copyright (c) 2015年 宋旭东. All rights reserved.
//

#import "focus_TableViewCell.h"
//#import "focus_tabViewModel.h"
#import "SDWebImageManager.h"
#import "AFNetworking.h"
#import "UIImageView+WebCache.h"
#import "UIViewExt.h"
#define kleftGap  16
#define kupGap   12
#define kDeviceWidth [UIScreen mainScreen].bounds.size.width
#define kImageViewWidth 40
#define kImageViewHeight 40
#define kLabelWidth [UIScreen mainScreen].bounds.size.width*0.35
#define kLabelHeight 60

@implementation focus_TableViewCell

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self initSubViews];
        
        //self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        self.backgroundColor=[UIColor clearColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
    }
    return self;
}

- (void)initSubViews
{
    _baseView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kDeviceWidth, self.height)];
    [self.contentView addSubview:_baseView];
    
    // 图片
    _imageView = [[UIButton alloc] initWithFrame:CGRectZero];
    [_baseView addSubview:_imageView];
    
    // 名字
    _nameLabel = [[UILabel alloc] initWithFrame:CGRectZero];
    _nameLabel.backgroundColor = [UIColor whiteColor];
    _nameLabel.font = [UIFont boldSystemFontOfSize:16];
    [_baseView addSubview:_nameLabel];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    //首图预览
    _imageView.frame = CGRectMake(kleftGap, kupGap, self.height - 2*kupGap, self.height - 2*kupGap);
    _imageView.backgroundColor=[UIColor whiteColor];
    
    UIImageView *image = [[UIImageView alloc]initWithFrame:_imageView.bounds];
    [_imageView addSubview:image];
    
    [image  setImageWithURL:[NSURL URLWithString:self.focustabViewModel.avatar] placeholderImage:[UIImage imageNamed:@"default_head"]];
    
    [_imageView setBackgroundImage:image.image forState:UIControlStateNormal];
    if (self.focustabViewModel.avatar.length<1) {
         [_imageView setBackgroundImage:[UIImage imageNamed:@"default_head"] forState:UIControlStateNormal];
    }
    
//    
//    _imageView.layer.cornerRadius = _imageView.frame.size.height/2.0;
//    _imageView.layer.masksToBounds = YES;
//    
//    _imageView.layer.borderWidth = 0;
    
//    [_imageView addTarget:self action:@selector(headClick) forControlEvents:UIControlEventTouchUpInside];
   
    
    //分隔线
    UIImageView *downDivider = [[UIImageView alloc] initWithFrame:CGRectMake(3, self.height, kDeviceWidth-6, 0.8)];
    downDivider.image = [UIImage imageNamed:@"gray_line"];
    
    [self.contentView addSubview:downDivider];

    
    // 标题
   // _nameLabel.frame = CGRectMake(_imageView.right+5, 30, kLabelWidth, kLabelHeight);
    
    //_nameLabel.text=@"犀牛哥要peace";
    NSString *text = self.focustabViewModel.username;
   
    _nameLabel.textColor = [UIColor blackColor];
    _nameLabel.font = [UIFont systemFontOfSize:15];
    
    _nameLabel.frame = CGRectMake(_imageView.right + 10, 20,self.frame.size.width, 20);
    _nameLabel.center = CGPointMake(_nameLabel.center.x, _imageView.center.y);
    _nameLabel.text = text;
//    UITapGestureRecognizer *headTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(headClick)];
//    [_baseView addGestureRecognizer:headTap];
}
//发通知
- (void)headClick
{

}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
